xquery version "0.9-ml"

(: $root is a string representing the root node from which the id will be checked and the node to be updated will be calculted 
$id is the id of the node to update
$node is the node to update from the the end of the provided root
$value is the value the nodes text will updated to

the entire query is put into a string and evaluated because when mixing standard query evaluations with those that had been evaluated from a string, an error was thrown stating that external nodes could not be updated

further, within the string, there is no guarantee that a node will have a value. Text() returns an error when evaluating agains an empty element. So when inserting values we need to construct the lowest level element repersentation of the value e.g. <tag>val</tag>
:)


let $arg_root := xdmp:get-request-field("root")
let $arg_element := xdmp:get-request-field("element")



(:these variables are for testing :)
(:
let $arg_root := "doc('jasonmonberg.xml')/jasonmonberg/portino"
let $arg_element := "<blendPart dateCreated='' dateModified=''><blendVarietal dateCreated='' dateModified=''/><blendPercentage dateCreated='' dateModified=''/></blendPart>"
:)

(:
return
xdmp:node-insert-child(
doc('wines.xml')/wines/wine[@id='112']/blend,
<blendPart><blendVarietal/><blendPercentage/></blendPart>
)
:)

let $s := concat(
	"xdmp:node-delete(
	",
	$arg_root
	,
	$arg_element
	,
	")"
	)

return
xdmp:eval($s),
<true>true</true>






